#!/usr/bin/env python
#-*- coding:utf-8 -*- 

import re

f = open('./test.txt')
context = f.read()	#读取
words = re.split(" |\s+|\,|\'|!|\?|\.", context)	#分割字符串
words = [x for x in words if x != '']	#去掉‘’
s = set(words) #建立无重复的单词的set
num = []

for each_s in s:
    count = 0
    for each_word in words:
        if each_s == each_word:
            count += 1
            num.append(count)
dic = zip(s, num)
f.close()
print(dict(dic))


